import Vue from "vue";
import VueRouter from "vue-router";
// 登陆注册页面
import Login from '@/components/Login.vue'
// 管理主页面
import Main from '@/components/Main.vue'
// 管理用户页面
import ManageUser from '@/components/ManageUser.vue'
// 管理角色权限页面
import ManageRule from '@/components/ManageRule.vue'
// 管理角色权限页面
import ManageEnt from '@/components/ManageEnt.vue'
// 管理App信息页面
import ManageApp from '@/components/ManageApp.vue'
// 管理菜单页面
import ManageMenu from '@/components/ManageMenu.vue'
// App下载页面
import BusAppDownload from '@/components/BusAppDownload.vue'
// 撰写文章页面
import BusWriteEssay from '@/components/BusWriteEssay.vue'
// 管理文章页面
import ManageEssay from '@/components/ManageEssay.vue'
// 管理文章类别页面
import ManageEssayType from '@/components/ManageEssayType.vue'
// 管理药品信息页面
import ManageMedi from "@/components/ManageMedi.vue";
// 管理疾病信息页面
import ManageDisease from "@/components/ManageDisease.vue";
// 管理医生信息页面
import ManageDr from "@/components/ManageDr.vue";
// 个人信息设置页面
import ManageDrSelf from "@/components/ManageDrSelf.vue";
// 数据大屏
import BusLargeScreen from "@/components/BusLargeScreen.vue";
// 首页
import Home from "../components/Home.vue";


Vue.use(VueRouter)

const router = new VueRouter({
    routes:[
        {
            path: '/',
            redirect: '/main' 
        },
        {
            path: '/login',
            component: Login
        },
        {
            path: '/main',
            component: Main
        },
        {
            path: '/manageUser',
            component: ManageUser
        },
        {
            path: '/manageRule',
            component: ManageRule
        },
        {
            path: '/manageEnt',
            component: ManageEnt
        },
        {
            path: '/manageApp',
            component: ManageApp
        },
        {
            path: '/manageMenu',
            component: ManageMenu
        },
        {
            path: '/busAppDownload',
            component: BusAppDownload
        },
        {
            path: '/busWriteEssay',
            component: BusWriteEssay
        },
        {
            path: '/manageEssay',
            component: ManageEssay
        },
        {
            path: '/manageEssayType',
            component: ManageEssayType
        },
        {
            path: '/manageMedi',
            component: ManageMedi
        },
        {
            path: '/manageDisease',
            component: ManageDisease
        },
        {
            path: '/manageDr',
            component: ManageDr
        },
        {
            path: '/manageDrSelf',
            component: ManageDrSelf
        },
        {
            path: '/busLargeScreen',
            component: BusLargeScreen
        },
        {
            path: '/home',
            component: Home
        }
    ]
})

//前驱方法 相当于过滤器 
// to表示要访问的路由信息的对象
// from表示将要离开的路由的信息对象
// next 是一个函数 调用它就表示放行，允许此次路由
router.beforeEach((to,from,next)=>{
    if (to.path === '/login') next()
    var loginUser = localStorage.getItem('loginUser');
    // 增加判断条件
    if (!loginUser && to.path !== '/login') return next('/login')
    next()
})

export default router